package com.clms.maintain.controller;

import com.clms.common.R;
import com.clms.maintain.utils.UploadUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @program: clms-maintain
 * @description: 文件上传
 * @author: 许鹏
 * @create: 2021-07-27 14:23
 **/
@RestController
@RequestMapping("maintain")
@ApiModel(value = "文件上传",description = "维修的图片上传")
public class UploadController {

        @PostMapping("upload")
        @ApiModelProperty(value = "维修记录的图片上传")
    public R upload(MultipartFile file){

            try {
                String upload = UploadUtil.Upload(file.getInputStream(), file.getOriginalFilename());
                System.out.println(upload);
                return R.ok().put("path", upload);
            } catch (IOException e) {
                e.printStackTrace();
                return R.error();
            }
        }
}
